package com.example.finalproject.experiments.intent

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.example.finalproject.R

class SecondActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_second)

        val textView = findViewById<TextView>(R.id.textView)
        val btnBack = findViewById<Button>(R.id.btnBack)

        // 获取传递过来的数据
        val data = intent.getStringExtra("extra_data")
        textView.text = data

        btnBack.setOnClickListener {
            val intent = Intent()
            intent.putExtra("result_data", "我是回传的信息")
            setResult(Activity.RESULT_OK, intent)
            finish()
        }
    }
}